package mx.com.switz.peliculas.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mx.com.switz.peliculas.dto.Socio;
import mx.com.switz.peliculas.service.PrestamoService;
import mx.com.switz.peliculas.service.SocioService;
import mx.com.switz.peliculas.service.impl.SocioServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("socio")
public class SocioController {

	@Autowired
	private SocioService socioService;
	@Autowired
	private PrestamoService prestamoService;

	private Socio s;
	
	@RequestMapping(value="verificar",method=RequestMethod.POST)
	public String verificaUsuario(HttpServletRequest request,HttpServletResponse response){
		
		this.s = socioService.obtenerUsuario(Integer.parseInt(request.getParameter("ID")));
		if (s==null)
			return "";//no hay socio
		else{
			return "socio/jtable";
		}
	}
	
	@RequestMapping("prestamos")
	@ResponseBody
	public List listarPrestamos(HttpServletRequest request) {

		return prestamoService.peliculasSocio(s);
	}
	
	

	

	@RequestMapping("guardar")
	public String goHola(){
		return "home";
	}
}
